<script>
import BaseUrl from "@/http/request/BaseUrl";
import TokenAxios from "@/http/request/TokenAxios";

export default {
  data(){
    return{
      // 当前每页显示多少条数据
      pageSize: 6,
      //分页相关数据
      currentPage: this.$router.currentRoute.query.page ? parseInt(this.$router.currentRoute.query.page) : 1,
      tableData: [],
      total: 0,
      url: [],
      noteContent: '',
      resourcesType: '',
      showImagedetail: false,
      openUpdateAduitByIds:false,
      inputType:{
        result:'',
      },
      ruleType:{
        result: [
          {required: true, message: '请至少给出一个序号', trigger: 'blur'}
        ],
    }
    }
  },
  methods:{
    //  查看图片详情
    selectImagedetail(note) {

      this.showImagedetail = true;
      this.noteContent = note.noteContent;
      console.log(note.noteContent);
      let urls = BaseUrl.ADMIN_CONTENT + "/admin/video/" + note.videoId + "/picture";
      TokenAxios.get(urls).then((response) => {
        let JsonResult = response.data;
        if (JsonResult.state == 20000) {
          this.url = JsonResult.data; // 将返回的数据赋值给picUrl数组
          console.log(JsonResult.data)
        } else {
          // 处理状态不为 20000 的情况
        }
      }).catch((error) => {
        // 处理请求错误
        console.error(error);
      });
    },
    //修改分类窗口显示
    openUpdateTypeById(note){
      this.openUpdateAduitByIds=true
      this.editId=note.id
      this.editNoteId=note.noteId
      this.editauthorId=note.authorId
      this.editResult=note.result
      this.editComplaintNumber=note.complaintNumber
      console.log(this.editId)
      console.log(this.editNoteId)
      console.log(this.editauthorId)
    },
    //修改分类名
    updateAuditById(note){
      console.log('当前页面的result：', this.result);
      let requestBody = {
        id:this.editId,
        complaintNumber:this.editComplaintNumber,
        result:note.result,
        noteId:this.editNoteId,
        authorId:this.editauthorId
      }
      let url = BaseUrl.ADMIN_COMPLAINT+'/admin/video/complaint/audit/';
      console.log(requestBody);
      TokenAxios.post(url,requestBody).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.$message({
            message: '成功!',
            type: 'success'
          });
          location.reload()
          console.log(jsonResult)
        } else {
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      }).catch((error) => {
        console.log('请求出错:', error);
      });
    },
// 切换分页
    handleCurrentChange(page) {
      // 修改当前页码时，使用 $router.push 而不是 $router.replace，保留浏览器的历史记录
      this.$router.replace('?page=' + page);
      this.loadUserList(page); // 将当前页码传递给 loadUserList 方法
    },
    loadUserList() {
      console.log('开始加载用户列表');
      let page = this.$router.currentRoute.query.page;
      console.log('开始加载用户列表，页码为', page);
      if (!page) {
        page = 1;
      }
      let url = BaseUrl.ADMIN_COMPLAINT + '/admin/video/complaint/listNotProcessed?pageNum=' + page+'&pageSize='+this.pageSize;

      TokenAxios.get(url,page).then((response) => {
        console.log('当前页码：', this.currentPage);
        console.log('每页显示条数：', this.pageSize);
        console.log('请求 URL：', url);
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.tableData = jsonResult.data.list;
          this.resourcesType = jsonResult.data;
          console.log(this.resourcesType)
          this.currentPage = jsonResult.data.currentPage;
          this.pageSize = jsonResult.data.pageSize;
          this.total = jsonResult.data.total;
          console.log('用户列表数据：', this.tableData);
          console.log('当前页码：', this.currentPage);
          console.log('每页显示条数：', this.pageSize);
          console.log('总条数：', this.total);
        } else {
          let title = '操作失败';
          this.$alert(jsonResult.message, title, {
            confirmButtonText: '确定',
            callback: action => {
            }
          })
        }
      })
    }
  },
  mounted(){
    let page = this.$route.query.page; // 通过 $route 获取当前页码
    this.loadUserList(page); // 将当前页码传递给 loadUserList 方法
  },
}
</script>


<template>
  <div>
    <!--面包屑导航区域-->
    <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-bottom: 20px;overflow: hidden">
      <el-breadcrumb-item :to="{ path: '/admin/index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>笔记审核</el-breadcrumb-item>
      <el-breadcrumb-item>未处理</el-breadcrumb-item>
    </el-breadcrumb>


    <el-card>
      <el-table :data="tableData"
                border stripe
                style="margin-bottom: 20px;overflow: hidden">
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column
            prop="videoId"
            label="视频ID"
        >
        </el-table-column>

        <el-table-column label="视频封面" width="180" align="center" prop="url">
          <template slot-scope="scope">
            <div style="width: 115px;height: 115px;overflow: hidden;position: relative;top: 18px">
              <img :src="scope.row.url" width="100%" height="100%" style="object-fit: cover;">
            </div>
            <br>
            <el-button type="text" @click="selectImagedetail(scope.row)" style="margin-right: 55px">查看详细</el-button>
            <el-dialog
                title="视频封面"
                :visible.sync="showImagedetail"
                width="50%"
                center
                @close="handleDialogClose"
            >
              <el-row>
                <el-col span:12>
                  <el-carousel trigger="click" height="600px">
                    <el-carousel-item>
                      <el-image fit="scale-down" :src="url.coverUrl" style="width: 100%; height: 100%"/>
                    </el-carousel-item>
                  </el-carousel>
                </el-col>
                <el-col span:12>
                  <p>{{ noteContent }}</p>
                </el-col>
              </el-row>
            </el-dialog>
          </template>
        </el-table-column>

        <el-table-column
            prop="complaintNumber"
            label="投诉单号"
            :show-overflow-tooltip="true"
        ></el-table-column>

        <el-table-column
            prop="ruleTypeName"
            label="违规类型"
        ></el-table-column>

        <el-table-column
            prop="content"
            label="违规内容描述"
            align="center"
            :show-overflow-tooltip="true"
        ></el-table-column>

        <el-table-column
            prop="authorName"
            label="作者昵称"
            align="center"
            :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
            prop="userName"
            label="投诉人昵称"
            align="center"
            :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
            prop="createTime"
            label="创建时间"
        >
        </el-table-column>
        <el-table-column
            prop="updateTime"
            label="修改时间"
        >
        </el-table-column>
        <el-table-column
            label="操作"
            width="220">
                    <template slot-scope="scope">
                      <!--          修改分类-->
                      <el-tooltip
                          class="item"
                          effect="dark"
                          content="修改分类名"
                          placement="top"
                          enterable
                      >
                        <el-button
                            type="warning"
                            icon="el-icon-setting"
                            size="mini"
                            @click="openUpdateTypeById(scope.row)"
                        ></el-button>

                      </el-tooltip>
                    </template>
        </el-table-column>
      </el-table>
      <!--分页区域-->
      <el-pagination
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :hide-on-single-page="true"
          :page-size="pageSize"
          layout="total, prev, pager, next,jumper"
          :total="total"
          background
      >
      </el-pagination>

      <!--    修改窗口-->
      <el-dialog
          style="text-align: center"
          title="修改违规分类"
          width="40%"
          :visible.sync="openUpdateAduitByIds"
      >
        <el-form :model="inputType" :rules="ruleType" ref="inputType" >

          <el-radio-group v-model="inputType.result">
            <el-radio  label="0">举报无效</el-radio>
            <el-radio  label="1">删除内容</el-radio>
            <el-radio  label="2">封禁用户</el-radio>
          </el-radio-group>

        </el-form>

        <el-button @click="openUpdateAduitByIds = false">取 消</el-button>
        <el-button
            type="primary" @click="updateAuditById(inputType)" size="small" style="margin-top: 20px"
        >确 定</el-button>
      </el-dialog>
    </el-card>
  </div>
</template>


<style scoped>

</style>